// 把链表最大的节点移动到结尾


// 没有引用有点难
// 只有两个元素时还有bug

#include "../linklist.h"
#include <stdio.h>


void MaxToTail(LinkList *list){
    LNode * pre = *list;
    if (pre->next == NULL || pre->next->next == NULL) return;
    LNode * p = pre->next;
    while (p!= NULL && p->next != NULL) {
        if (p->next->data > pre->next->data) {
            pre = p;
        }
        p = p->next;
    }
    p->next = pre->next;
    pre->next = pre->next->next;
    p->next->next = NULL;
}

int main(){
    LinkList list;
    InitList(&list);
    int nums[] = {100,15,1,114,58,45,23};
    for (int i=0; i<2; i++) {
        InsertElem(list, nums[i]);
    }
    PrintList(list);
    MaxToTail(&list->next);
    PrintList(list);
    return 0;
}